<script setup>
import Record from "@/pages/components/record.vue";
import Nodata from "@/pages/components/nodata.vue";
import { mySettle } from "@/services/reward";
import { nextTick, ref } from "vue";
import { onShow } from "@dcloudio/uni-app";
import skeletonview from "@/pages/components/skeleton.vue";
const skeletshow = ref(true);

const morefun = () => {
  uni.navigateTo({
    url: "/pages/servicereward/myreward/rewardlist",
  });
};
const dettofun = (id) => {
  uni.navigateTo({
    url: `/pages/servicereward/myreward/awaitClose?id=${id}`,
  });
};

const num = ref({});
const datalist = ref([]);
const shownodata = ref(false);
onShow(() => {
  getSettle();
});

async function getSettle() {
  shownodata.value = false;
  let res = await mySettle({
    page: 1,
    limit: 30,
  });
  num.value = res.data.sum;

  res.data.list.forEach((item, index) => {
    item.total = item.after_balance;
    item.balance = item.draw_balance;
    // item.title = item.account_type_name
    item.type_class = item.class_text;
  });
  datalist.value = res.data.list;
  // datalist.value = [{}]
  skeletshow.value = false;
  shownodata.value = true;
}
const popup = ref(null);
// nextTick(() => {
// 	popup.value.open()
// })

const clossfun = () => {
  popup.value.close();
};

const goreward = () => {
  // userisreal
  uni.navigateTo({
    url: "/pages/servicereward/myreward/balance",
  });
  return;
  if (
    uni.getStorageSync("userisreal") &&
    uni.getStorageSync("userisreal") === 1
  ) {
    uni.navigateTo({
      url: "/pages/myreward/balance",
    });
  } else {
    popup.value.open();
  }
};

const goresl = () => {
  uni.switchTab({
    url: "/pages/my/index",
  });
};
</script>

<template>
  <skeletonview
    v-if="skeletshow"
    style="
      z-index: 999;
      background-color: #fbf8f3;
      position: absolute;
      top: 0;
      left: 0;
    "
  >
  </skeletonview>
  <view class="content" v-if="!skeletshow">
    <view class="content-top">
      <view class="content-title">
        <view class="content-title-num">
          <view class="content-title-num-title">余额(元)</view>
          <view class="content-title-nums">
            <up-count-to
              :startVal="0"
              :endVal="num.draw_earn ? num.draw_earn : 0"
              separator=","
              :decimals="2"
              :useEasing="true"
              :duration="500"
              fontSize="36"
              color="#FFFFFF"
              :bold="true"
            ></up-count-to
          ></view>
        </view>
        <view class="content-title-right" @click="goreward">结算</view>
      </view>

      <view class="content-top-bt">
        <view class="content-top-bt-left">
          <view class="content-top-bt-left-title">
            <text>预估收益（交易未完成的待出账收益）</text>
            <!-- <image
              src="@/pages/servicereward/static/reward/icons_ach_more.png"
              mode="widthFix"
            ></image> -->
          </view>
          <view class="content-top-bt-left-num">
            <up-count-to
              :startVal="0"
              :endVal="num.predict_earn ? num.predict_earn : 0"
              separator=","
              :decimals="2"
              :useEasing="true"
              :duration="500"
              fontSize="16"
              color="red"
              :bold="true"
            ></up-count-to
          ></view>
        </view>
        <!-- <view class="content-top-bt-left content-top-bt-right">
          <view class="content-top-bt-left-title">
            <text>本月实际收益(元)</text>
            <image
              src="@/pages/servicereward/static/reward/icons_ach_more.png"
              mode="widthFix"
            ></image>
          </view>
          <view class="content-top-bt-left-num"
            ><up-count-to
              :startVal="0"
              :endVal="num.month_earn ? num.month_earn : 0"
              separator=","
              :decimals="2"
              :useEasing="true"
              :duration="500"
              fontSize="16"
              color="#FFFFFF"
              :bold="true"
            ></up-count-to
          ></view>
        </view> -->
      </view>
    </view>

    <uni-popup ref="popup" type="center" :animation="false">
      <view class="my-reft">
        <view class="my-reft-code" @click="clossfun">
          <image
            src="@/pages/servicereward/static/reward/closs.png"
            mode="widthFix"
          ></image>
        </view>
        <view class="my-reft-content">
          <image
            src="@/pages/servicereward/static/reward/icon-id.png"
            mode="widthFix"
          ></image>
        </view>
        <view class="my-reft-title"> 请补全您的实名信息 </view>
        <view class="my-reft-dec"> 请先去实名认证哦 </view>

        <view class="my-reft-bt" @click="goresl"> 实名认证 </view>
      </view>
    </uni-popup>

    <!-- '	More', "detTo" -->
    <view class="data-list">
      <Record
        :title="'奖励金额变动明细'"
        :datelist="datalist"
        @More="morefun"
        @detTo="dettofun"
      ></Record>
    </view>
    <Nodata v-if="datalist.length === 0 && shownodata" dec="暂未内容~"></Nodata>
  </view>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
